package judlawei.readfile;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;





public class Reader {

    private static Reader reader = null;
    private final String lineSeparator = System.getProperty("line.separator");

    public static Reader getInstance() {

        if (reader == null)
            reader = new Reader();
        return reader;
    }

    public String getText(File f){
        BufferedReader buffer = null;
        try {
            buffer = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return reader.getStringFile(buffer);
        
    }

    private String getStringFile(BufferedReader b) {

        StringBuffer buffer = new StringBuffer();
        String line = null;
        try {
            line = b.readLine();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        while (line != null){
            
            buffer.append(line);
            buffer.append(lineSeparator);
            try {
                line = b.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return buffer.substring(0);

    }

}
